﻿Imports NHibernate
Imports NHibernate.Cfg
Public Class NhibernateSessionFactory
    Private Shared miConfig As New Configuration
    Private Shared miFactory As ISessionFactory
    Private Shared _TestMode As Boolean

    Public Shared Function getSessionFactory() As ISessionFactory
        If miFactory Is Nothing Then
            miConfig.Configure()
            If _TestMode Then miConfig.SetProperty("connection.connection_string", " Database=todomicrosolutionpackv1test;Data Source=localhost;User Id=root;Password=tedeladi86;")
            miFactory = miConfig.BuildSessionFactory
            NhibernateValidator.initValidator(miConfig)

        End If
        Return miFactory
    End Function

    Public Shared Function getSession() As ISession
        Return getSessionFactory.OpenSession()
    End Function

    Public Shared Property testMode As Boolean
        Get
            Return _TestMode
        End Get
        Set(ByVal value As Boolean)
            _TestMode = value
        End Set
    End Property
End Class
